<template>
	<view class="container">
		<template v-if="empty">
		    <view class="tabsContent">
				<u-empty mode="data" width="280" height="280" textSize="28"
		     icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无公告信息"></u-empty>
		    </view>
		</template>
		<template v-else>
			<view class="notice-box" v-for="item in list" @click="toNociteDetails(item)">
				<view class="notice-time"><text>{{item.creatTime}}</text></view>
				<view class="content">
					<view class="notice-title">{{item.title}}</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	import api from '@/api/api.js';
	export default {
		name: '',
		components: {},
		data() {
			return {
				pageNum:1,
				pageSize:10,
				list:[],
				id:null,//详情id
				num:null,//条数
				empty:false,//是否为空
			}
		},
		created() {
			this.getNotice()
		},
		mounted() {},
		destroyed() {},
		methods: {
			// 获取公告列表
			getNotice(){
				let data={
					pageNum:this.pageNum,
					pageSize:this.pageSize,
					type:1,//1公告  2广告  3新闻
				}
				api.getNotice(data).then(res=>{
					if(res.data.code==601){
						this.empty=true
					}else if(res.data.code==200){
						this.list=this.list.concat(res.data.rows)
						this.num=Math.ceil(res.data.total/this.pageSize)//总条数除一页多少条向上取整
						this.pageNum++
					}
				})
			},
			// 点击跳转公告详情
			toNociteDetails(item){
				uni.$u.route({
					type:"navigateTo",
					url: "/pages/notice/details",
					params: {
						id: item.id
					}
				});
			}
		},
		onReachBottom(){
		    // 触底的时候请求数据，即为上拉加载更多
		    console.log('触底')
			if(this.pageNum<=this.num){
				this.getNotice()
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			const _that=this
			_that.pageNum=1
			_that.list=[]
			_that.num=null
			setTimeout(function () {
				uni.stopPullDownRefresh();
				_that.getNotice();
			}, 1000);
		}
	}
</script>

<style lang="scss" scoped>
.container {
	width: calc(100% - 32rpx);
	padding: 16rpx;
	.tabsContent {
		width: 100%;
		background-color: #FFFFFF;
		height: 1000rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.notice-box{
		.notice-time{
			text-align: center;
			margin-bottom: 30rpx;
			text{
				background-color: #d5d5d5;
				padding: 8rpx 16rpx;
				color: #8a8a8a;
				font-size: 24rpx;
				border-radius: 30rpx;
			}
			
		}
		.content{
			background-color: #fff;
			margin-bottom: 64rpx;
			padding: 20rpx;
			border-left: 8rpx solid #17abe3;
			border-radius: 8rpx;
			.notice-title{
				font-size: 28rpx;
				font-weight: bold;
			}
		}
	}
}
</style>
